//------------------------------------------
//			string prototype
//------------------------------------------
String.prototype.format = function(strFormat) 
{ 
    var args = arguments;             
    return this.replace(    /\{(\d+)\}/g, 
                            function(m,i)
                            { 
                                return args[i]; 
                            }
                        ); 
} 

String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.trimall = function()
{
	return this.replace(/\s*/g, "");
}

String.prototype.replaceAll = function(s1,s2)
{
	return this.replace(new RegExp(s1,"gm"),s2);    
}



//------------------------------------------
//			string function
//------------------------------------------
var g_sTailSet = [	
							"中西餐厅", "自助烤肉","海鲜酒店","家常菜馆","休闲餐厅",
							"烤肉店", "老菜馆","烧烤店","饺子馆","料理店","火锅城","海鲜坊","烤全鱼",
							"家常菜","海鲜馆",
							"总店", "饭店", "面馆", "火锅", "饭庄",
							"食府","餐厅","酒楼","酒店",
							"店"
				];
function getFandian(strSrc)
{
	var strTmp = strSrc.trimall();

	//1. 如果存在分店，提取店名
	function getFendian(src)
	{
		var re = /[\(（\)）]/i;		// 创建正则表达式模式。
		var r = src.split(re);			// 尝试匹配搜索字符串。	

		return [r.length, r[0]];
	}
	var rtn = getFendian(strTmp);
	if(rtn[0]>1)
		return rtn[1];

	//2.如果店名少于5，直接返回，避免处理
	if(strTmp.length<=5)
		return strTmp;

	//3.如果有特殊结尾词汇，去掉
	function removeTail(src)
	{
		var rtn = src;
		var len = src.length;
		var sSet = ["", src.substr(len-1), src.substr(len-2),src.substr(len-3), src.substr(len-4)];
		for(var i=0; i<g_sTailSet.length; i++)
		{
			len = g_sTailSet[i].length;
			if(len>4||len==0)
				continue;
			
			if(sSet[len]==g_sTailSet[i])
			{
				rtn = src.substr(0, src.length-len);
				break;
			}
		}

		return rtn;
	}
	return removeTail(strTmp);
}

function test(pSheet)
{
	alert(g_sTailSet.length);
	alert(pSheet);
	for(var i=0; i<g_sTailSet.length; i++)
	{
		SetCellText(pSheet, i+1, 4, g_sTailSet[i]);		
	}
}

//------------------------------------------
//			string global
//------------------------------------------
	//-显示输入提示-
function txtTipInput(vObj, strTip)
{
    var m_oTxt    = typeof(vObj)=="object" ? vObj : document.getElementById(vObj);
    if(m_oTxt==null)
        return;
    
    function in_onFocus()
    {               
        if(m_oTxt.value=="" || m_oTxt.value==strTip)    
        {
            m_oTxt.value = "";
        }
    }
    
    function in_onBlur()
    {
        if(m_oTxt.value=="")
            m_oTxt.value = strTip;
    }
    
    m_oTxt.onfocus = in_onFocus;
    m_oTxt.onblur = in_onBlur;
    in_onBlur();
}

function json2str(o) 
{
	var arr = [];
	var fmt = function(s) 
	{
	   if (typeof s == 'object' && s != null) 
		   return json2str(s);
	   return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s;
	}
	for (var i in o) 
		arr.push("'" + i + "':" + fmt(o[i]));
	return '{' + arr.join(',') + '}';
}


//------------------------------------------
//			string alghothrim
//------------------------------------------
function LCS(str1, str2)
{
	var	strLarge, strLittle;
	var nLen1 = str1.length;
	var nLen2 = str2.length;

	//-确保大数据在前-
	if (nLen1< nLen2)
	{
		strLarge = str2;
		strLittle = str1;
		nLen1 = strLarge.length;
		nLen2 = strLittle.length;
	}
	else
	{
		strLarge = str1;
		strLittle = str2;
	}

	//-初始化标记-
	var	flag = new Array();
	for(i=0; i<nLen1; i++)
	{
		flag[i] = 0;
	}

	//-循环判断-
	var nLength = 0, nEnd=0, i, j;
	var strTmp1, strTmp2
	for(i=0; i<nLen2; i++)
	for(j=nLen1-1; j>=0; j--)
	{
		strTmp2 = strLittle.substr(i, 1);
		strTmp1 = strLarge.substr(j, 1);
		if (strTmp2==strTmp1)
		{
			if (i==0 || j==0)
				flag[j] = 1;
			else
				flag[j] = flag[j-1]+1
		}
		else
		{
			flag[j]=0;
		}

		if(flag[j]>nLength)
		{
			nLength = flag[j];
			nEnd = j;
		}
	}
	
	var rtn = strLarge.substr(nEnd-nLength+1, nLength);

	return rtn;
}


//------------------------------------------
//			string regexp
//------------------------------------------
//-正则表达式匹配判断-
function RegexpMatch(strPattern, strSrc)
{
    var re = new RegExp(strPattern, "gi");
	var bMatch = re.test(strSrc);
	return bMatch;
}

//-正则表达式提取-
function RegexpPick(strPattern, strSrc, nIndex)
{
	var rtn="";
    var re = new RegExp(strPattern, "gi");
	var r = re.exec(strSrc);
    if (r && r.length>0)
		rtn = r[nIndex];

	return rtn;
}

//-正则表达式替换-
function RegexpReplace(strPattern, strSrc, strReplace)
{
    var re = new RegExp(strPattern, "gi");
	var rtn = strSrc.replace(re, strReplace);
	return rtn;
}